<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="Dashboard">
  <meta name="keyword" content="Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, Retina">
  <title>代码生成</title>

  <link href="img/favicon.png" rel="icon">
  <link href="img/favicon.png" rel="icon">
  
  <link href="lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="lib/font-awesome/css/font-awesome.css" rel="stylesheet" />
  
  <link rel="stylesheet" type="text/css" href="css/zabuto_calendar.css">
  <link rel="stylesheet" type="text/css" href="lib/gritter/css/jquery.gritter.css" />
  
  <link href="css/style.css" rel="stylesheet">
  <link href="css/style-responsive.css" rel="stylesheet">
  <script src="lib/chart-master/Chart.js"></script>
</head>

<body>
  <section id="container">
    <header class="header black-bg">
      <div class="sidebar-toggle-box">
        <div class="fa fa-bars tooltips" data-placement="right" data-original-title="隐藏/显示侧边栏"></div>
      </div>
      <!--logo start-->
      <a href="index.html" class="logo"><b>EASY-WEB</b></a>
      <!--logo end-->

      <div class="top-menu">
        <ul class="nav pull-right top-menu">
          <li><a class="logout" href="login.html">注销</a></li>
        </ul>
      </div>
    </header>
    <aside>
      <div id="sidebar" class="nav-collapse ">
        <!-- sidebar menu start-->
        <ul class="sidebar-menu" id="nav-accordion">
          <p class="centered"><a href="profile.html"><img src="img/head.jpg" class="img-circle" width="80"></a></p>
          <h5 class="centered">easy-web</h5>
          <li class="mt">
            <a href="easy-web">
              <i class="fa fa-dashboard"></i>
              <span>主页</span>
              </a>
          </li>
          <li>
            <a href="easy-swagger">
              <i class="fa fa-dashboard"></i>
              <span>swagger</span>
              </a>
          </li>
          <li>
            <a href="easy-code">
              <i class="fa fa-dashboard"></i>
              <span>代码生成</span>
              </a>
          </li>
        </ul>
      </div>
    </aside>
      <section id="main-content">
      <section class="wrapper" style="margin-left:5%;color:#3B3B3B;text-align:center"> 
	        <div class="row mt">
	          <div class="col-md-1"><p class="form-control-static">模块作者</p></div>
	          <div class="col-md-8"><input type="text" class="form-control round-form" placeholder="easy-web代码生成工具" id="module_auth" value=""></div>
	        </div>
	        <div class="row mt">
	          <div class="col-md-1"><p class="form-control-static">模块路径</p></div>
	          <div class="col-md-8"><input type="text" class="form-control round-form" placeholder="模块路径绝对地址，默认地址<D://modules>" id="module_path" value=""></div>
	        </div>
	       
	        <div class="row mt">
	          <div class="col-md-1"><p class="form-control-static">模块业务</p></div>
	          <div class="col-md-10">
	                <div class="row mt">
			          <div class="col-md-3"><p class="form-control-static">实体名</p></div>
			          <div class="col-md-3"><p class="form-control-static">数据表</p></div>
			          <div class="col-md-4"><p class="form-control-static">包路径</p></div>
			        </div>
			        <div class="row mt" id = "defaultText">
			          <div class="col-md-3 entity_name"><input type="text" class="form-control round-form" placeholder="demo" ></div>
			          <div class="col-md-3 entity_table"><input type="text" class="form-control round-form" placeholder="db_demo" ></div>
			          <div class="col-md-4 entity_path"><input type="text" class="form-control round-form" placeholder="默认<D:/modules/实体名小写>"></div>
			       </div>
		           <div class="col-md-2">
		             <p class="form-control-static">
		                <a href="javascript:;" id="insert"><img src="img/insert.png" class="img-circle" width="28">插入新行</a>
		             </p>
		          </div>
	           </div>
	         </div>
	         <div class="row mt">
	             <div class="col-md-9">
	                <button type="button" class="btn btn-primary" id="excuteGenerate">生成代码</button>
	             </div>
	         </div>
      </section>
    </section>
  <!-- js placed at the end of the document so the pages load faster -->
  <script src="lib/jquery/jquery.min.js"></script>

  <script src="lib/bootstrap/js/bootstrap.min.js"></script>
  <script class="include" type="text/javascript" src="lib/jquery.dcjqaccordion.2.7.js"></script>
  <script src="lib/jquery.scrollTo.min.js"></script>
  <script src="lib/jquery.nicescroll.js" type="text/javascript"></script>
  <script src="lib/jquery.sparkline.js"></script>
  <!--common script for all pages-->
  <script src="lib/common-scripts.js"></script>
  <script type="text/javascript" src="lib/gritter/js/jquery.gritter.js"></script>
  <script type="text/javascript" src="lib/gritter-conf.js"></script>
  <!--script for this page-->
  <script src="lib/sparkline-chart.js"></script>
  <script src="lib/zabuto_calendar.js"></script>
  <script type="application/javascript">
    $(function(){
    	
    	var elementText = $("#defaultText").html();
    	var entity_names = null;
    	var entity_tables = null;
    	var entity_paths = null;
    	
    	$("#insert").bind("click",function(){
    		insert(elementText);
    	});
    	$("#excuteGenerate").bind("click",function(){
    		var module_path = $("#module_path").val();
    		var module_auth = $("#module_auth").val();
    		init();
    		var module = {}
    		module.module_path = $("#module_path").val();
    		module.module_auth = $("#module_auth").val();
    		module.entity_names = entity_names;
    		module.entity_tables = entity_tables;
    		module.entity_paths = entity_paths;
    		$.ajax({ 
    			type : "POST",
    			url: "code/excute",
    			dataType: 'json',//必须指定
    			contentType: 'application/json',//必须指定
    			data: JSON.stringify(module), 
    			success: function(res){
    	           alert(res);
    	        }
    		});
    	})
    	
    	function insert(elementText){
    		init();
    		$("#defaultText").html(elementText+"<br><br><br>"+$("#defaultText").html());
    		restore();
    	}
    	
    	function init(){
    		entity_names = getValues($(".entity_name"));
        	entity_tables = getValues($(".entity_table"));
        	entity_paths = getValues($(".entity_path"));
    	}
    	
    	function restore(){
    		initValues($(".entity_name"), entity_names);
    		initValues($(".entity_table"), entity_tables);
    		initValues($(".entity_path"), entity_paths);
    	}
    	
    	function initValues(obj, values){
    		var i = 0;
    		obj.each(function(){
    			if(i>0){
        			$(this).find("input").val(values[values.length-i])
    			}
    			i++;
    		});
    	}
    	
    	function getValues(obj){
    		var values = [];
    		var i = 0;
    		obj.each(function(){
    			values[i] = $(this).find("input").val();
    			i++;
    		});
    		return values;
    	}
    })
  </script>
  <script type="application/javascript">
    $(document).ready(function() {
      $("#date-popover").popover({
        html: true,
        trigger: "manual"
      });
      $("#date-popover").hide();
      $("#date-popover").click(function(e) {
        $(this).hide();
      });

      $("#my-calendar").zabuto_calendar({
        action: function() {
          return myDateFunction(this.id, false);
        },
        action_nav: function() {
          return myNavFunction(this.id);
        },
        ajax: {
          url: "show_data.php?action=1",
          modal: true
        },
        legend: [{
            type: "text",
            label: "Special event",
            badge: "00"
          },
          {
            type: "block",
            label: "Regular event",
          }
        ]
      });
    });

    function myNavFunction(id) {
      $("#date-popover").hide();
      var nav = $("#" + id).data("navigation");
      var to = $("#" + id).data("to");
      console.log('nav ' + nav + ' to: ' + to.month + '/' + to.year);
    }
  </script>
</body>

</html>
